#!/usr/bin/env python
# encoding:utf-8
'''
将文档转换为表格，5000条数据为一个表格
'''
import xlwt
class data_Exp(object):
    def add_list(self,file):
        self.file = file
    #读取文件的指定行并写入新文件
        num = 0
        l = []
        lfile = open(file,'r')
    #将表格数据转换为列表
        for line in lfile.readlines():
            l.append(line)
            num +=1
        lfile.close()
        # print num  ,len(l) ,'123'
        print(num  ,len(l) ,'123')
    # 将列表数据每次取出5000存到对应的表格里
        x = 0
        for y in range(0, int((len(l) / 5000) + 1)):
            workbook = xlwt.Workbook(encoding='ascii')  # 设置表格字符集
            worksheet = workbook.add_sheet('data')  # 设置工作簿名称
            for a in l[y * 5000:(y + 1) * 5000]:
                # print x , a , '234'
                worksheet.write(x,0,a)
                x = x+1
            workbook.save('d:/%d.xls'%y)  # 将表格内容保存在本地
            print ('%d.xls导出成功，在D盘' % y)
            x = 0

#调用类
if __name__ == '__main__':
    a = data_Exp()
    a.add_list('d:/abc.txt')